unit oPedActor;

interface

uses uOSPABA, oPedestriansManager, oPathsManager, oPedestrian, oEntity, oVector, Dialogs, oStats;

type
  TManazerActor = class(tActorManager)
    public
      constructor create(paID: Cardinal;paAgent: TCommonAgent;paString: String);
      procedure ProcessMessage(var paMessage: TMessageForm); override;
  end;

  TPedActor = class(TActor)
    private
      aType: Integer;
      aPedestrian: TPedestrian;
      aCrowdTightning: Real;
      aPath: TPathsManager.TPathType;
      aTarget: TEntity;
      aTargetMatrix: fMatrix;
      aWaiting: TWaitStat;
      aActId: Integer;
      procedure setTarget(Value: TEntity);
    public
      property StatWaiting: TWaitStat read aWaiting write aWaiting;
      property Path: TPathsManager.TPathType read aPath write aPath;
      property Pedestrian: TPedestrian read aPedestrian write aPedestrian;
      property Typ : integer read aType;
      property Target: TEntity read aTarget write setTarget;
      property ActId: Integer read aActId write aActId;
      property TargetMatrix: fMatrix read aTargetMatrix write aTargetMatrix;
      constructor Create(parMySim: tSimulation; parParentAgent: tAgent; paType: Integer; paID: Integer);
      destructor Destroy; override;
      procedure GoAhead;
  end;

implementation

uses oSimulation,SysUtils, oBA, oSS, oAgentLevel;

{ TPedActor }

constructor TPedActor.Create(parMySim: tSimulation;parParentAgent: tAgent; paType: Integer; paID: Integer);
begin
  inherited create(paID,parMySim,parParentAgent);
  aWaiting := nil;
  aType := paType;
  aPedestrian := nil;
  aPath := nil;
  aTarget := nil;
  aTargetMatrix := nil;
  aActId := 0;
  TManazerActor.create(IDActorManager,self,NoMOPN);
end;

destructor TPedActor.destroy;
begin
  aWaiting.Free;
  aPedestrian := nil;
  aPath := nil;
  aTarget := nil;
  aTargetMatrix := nil;
  inherited;
end;

procedure TPedActor.GoAhead;
begin
  if aActId + 1 < aPath.WayPoints.Count then
    begin
      Inc(aActId);
      aTarget := aPath.WayPoints.Items[aActId];
    end;
end;

procedure TPedActor.setTarget(Value: TEntity);
begin
  aTarget := Value;
end;

{ TManazerActor }

constructor TManazerActor.create(paID: Cardinal; paAgent: TCommonAgent;
  paString: String);
begin
  inherited create(paID,paAgent,paString);
end;

procedure TManazerActor.ProcessMessage(var paMessage: TMessageForm);
var msg: TPSMessage;
    finished: boolean;
begin
  case paMessage.Code of

    mcGoal: begin
      //ShowMessage('start');
      tActor(MyAgent).TickSubscriber := true;
      paMessage.Free;
    end;

    mcTick: begin
      //ShowMessage('tick');
      finished := false;

      if TPedActor(MyAgent).Target = nil then finished := true
      else case TPedActor(MyAgent).aType of
        atBA: finished := BASim(TPedActor(MyAgent));
        atSS: finished := SSSim(TPedActor(MyAgent));
      end;

      if finished then begin
        msg := TPSMessage.Create(MySim,TPedActor(MyAgent));
        tActor(MyAgent).TickSubscriber := false;
        Done(msg);

      end;
    end;

  end;

end;

end.
